mount – matoken's blog https://matoken.org/blog Is there no plan B? Sat, 21 Dec 2024 22:40:58 +0000 ja hourly 1 https://wordpress.org/?v=6.8.3 https://matoken.org/blog/wp-content/uploads/2025/03/cropped-1865f695c4eecc844385acef2f078255036adccd42c254580ea3844543ab56d9-32x32.jpeg mount – matoken's blog https://matoken.org/blog 32 32 fuse-archiveでいろいろなアーカイブをfuse mount https://matoken.org/blog/2024/12/22/fuse-mount-various-archives-with-fuse-archive/ https://matoken.org/blog/2024/12/22/fuse-mount-various-archives-with-fuse-archive/#respond Sat, 21 Dec 2024 22:40:57 +0000 https://matoken.org/blog/?p=4291

アドベントカレンダーの時期ですね.本来のクリスマスに向けカレンダーを日に日にめくりお菓子が出てくる感じのものとは別に近年技術者向けの記事をクリスマスまで公開してくアドベントカレンダーもあります.
その中のFreeBSDアドベントカレンダーを見ていて以下の記事が気になりました.

FreeBSD 14からtarアーカイブをファイルシステムにマウントするtarfs(4)が入ったそうです.Linuxでfuse-zipとかは使ったことがあるけど他にもないかなと探してfuse-archiveを試してみました.

fuse-zipはFilesystem in Userspace(FUSE)経由でzipアーカイブをマウントできるものです.Debianパッケージもあるので導入や管理が楽です.

fuse-archiveはたくさんのアーカイブに対応した同じようなもののようです.

fuse-archiveのインストール

今回もDebian sid amd64環境に導入しました.
インストール方法は INSTALL.md に詳しいです.
ここではインストール時に DESTDIR を設定してホームディレクトリ以下にインストールしています.

$ sudo apt install libboost-container-dev libfuse-dev libarchive-dev \
                  g++ pkg-config make pandoc \
                  python3 (1)
$ git clone https://github.com/google/fuse-archive.git (2)
$ cd fuse-archive
$ make (3)
$ make check
$ DESTDIR=~/ make install (4)
install -D "out/fuse-archive" "/home/matoken//usr/bin/fuse-archive"
install -D -m 644 fuse-archive.1 "/home/matoken//usr/share/man/man1/fuse-archive.1"
$ which fuse-archive
/home/matoken/usr/bin/fuse-archive
  1. 関連パッケージの導入

  2. sourceのclone

  3. build

  4. DESTDIRを指定してインストール

fuse-archiveの利用

$ fuse-archive linux-6.8.2.tar.xz (1)
fuse-archive: Created mount point 'linux-6.8.2' (2)
$ mount | grep linux (3)
fuse-archive on /home/matoken/Downloads/linux-6.8.2 type fuse.fuse-archive (ro,nosuid,nodev,relatime,user_id=1000,group_id=1000)
$ grep linux /etc/mtab
fuse-archive /home/matoken/Downloads/linux-6.8.2 fuse.fuse-archive ro,nosuid,nodev,relatime,user_id=1000,group_id=1000 0 0
$ ls linux-6.8.2/linux-6.8.2/ (4)
COPYING  Documentation  Kconfig   MAINTAINERS  README  block  crypto   fs       init      ipc     lib  net   samples  security  tools  virt
CREDITS  Kbuild         LICENSES  Makefile     arch    certs  drivers  include  io_uring  kernel  mm   rust  scripts  sound     usr
$ head linux-6.8.2/linux-6.8.2/README (5)
Linux kernel
============

There are several guides for kernel developers and users. These guides can
be rendered in a number of formats, like HTML and PDF. Please read
Documentation/admin-guide/README.rst first.

In order to build the documentation, use ``make htmldocs`` or
``make pdfdocs``.  The formatted documentation can also be read online at:

$ touch linux-6.8.2/linux-6.8.2/Makefile (6)
touch: cannot touch 'linux-6.8.2/linux-6.8.2/Makefile': Read-only file system
$ fusermount -u linux-6.8.2 (7)
$ grep linux /etc/mtab
$ ls linux-6.8.2* (8)
linux-6.8.2.tar.xz
  1. fuse-archiveで適当なアーカイブをマウント(マウント時にはキャッシュに読み込むため少し時間がかかる)

  2. 拡張子を除いたファイル名のディレクトリがマウントポイントとして作成されマウントされた

  3. mountされているのを確認

  4. アーカイブ内のファイルにアクセス

  5. ファイルの中を確認

  6. 書き込みはできない

  7. unmount

  8. マウントポイントのディレクトリも消える

大きなアーカイブの利用
$ ls -s Qubes-R4.2.3-x86_64.iso
6748400 Qubes-R4.2.3-x86_64.iso
$ fuse-archive Qubes-R4.2.3-x86_64.iso (1)
fuse-archive: Cannot write to cache: No space left on device
$ fuse-archive -o nocache Qubes-R4.2.3-x86_64.iso (2)
fuse-archive: Created mount point 'Qubes-R4.2.3-x86_64'
$ ls Qubes-R4.2.3-x86_64
EFI  Packages  boot  images  repodata
  1. 大きなアーカイブだと容量不足で失敗することがある

  2. -o nocache オプションでキャッシュを無効にして舞うとすることが可能,ただし速度は大幅に低下する

アーカイブ内のアーカイブのマウント
$ mktemp -d
/tmp/tmp.ZJ1Sil9byy
$ fuse-archive Qubes-R4.2.3-x86_64/Packages/zlib-1.2.12-5.fc37.x86_64.rpm /tmp/tmp.ZJ1Sil9byy
fuse-archive: Using existing mount point '/tmp/tmp.ZJ1Sil9byy'
$ ls /tmp/tmp.ZJ1Sil9byy/
usr
パスワード付きzipファイル
$ find . -iname "*.txt" | zip -e -r -@ /tmp/test.zip
$ fuse-archive /tmp/test.zip
The archive is encrypted.
What is the passphrase that unlocks this archive?
> Got it!
fuse-archive: Created mount point '/tmp/test'

まとめ

fuse-archiveはこれまで試した類似ツールと比べて多くのファイル形式に対応していて高速です.アーカイブの中のファイルを確認するのにとても便利そうです.
ディストリビューションパッケージにあると便利ですが,DebianのWNPPを見ると無さそうです.RFPを投げるといいかもしれません.

環境

$ fuse-archive --version
fuse-archive version: 1.5
libarchive version: libarchive 3.7.4
bzlib version: 1.0.8, 13-Jul-2019
liblz4 version: 1.9.4
liblzma version: 5.6.3
libzstd version: 1.5.6
zlib version: 1.3.1
FUSE library version: 2.9.9
fusermount3 version: 3.14.0
using FUSE kernel interface version 7.19
$ dpkg-query -W libboost-container-dev libfuse-dev libarchive-dev g++ pkg-config make pandoc python3 git
g++     4:14.2.0-1
git     1:2.45.2-1.2
libarchive-dev:amd64    3.7.4-1.1
libboost-container-dev:amd64    1.83.0.2+b2
libfuse-dev:amd64       2.9.9-9
make    4.4.1-1
pandoc  3.1.11.1+ds-2
pkg-config:amd64        1.8.1-4
python3 3.12.7-1
$ lsb_release -dr
Description:    Debian GNU/Linux trixie/sid
Release:        n/a
$ arch
x86_64
]]>
https://matoken.org/blog/2024/12/22/fuse-mount-various-archives-with-fuse-archive/feed/ 0
qcow2 イメージをマウント https://matoken.org/blog/2018/09/26/mount-qcow2-image/ https://matoken.org/blog/2018/09/26/mount-qcow2-image/#respond Wed, 26 Sep 2018 12:39:40 +0000 http://matoken.org/blog/?p=2141

qemuやKVMでよく使われるqcow2イメージのマウントを行いました.

イメージの確認
$ sudo qemu-img info /var/lib/libvirt/images/Debian.qcow2
image: /var/lib/libvirt/images/Debian.qcow2
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 20G
cluster_size: 65536
Format specific information:
	compat: 1.1
	lazy refcounts: true
	refcount bits: 16
	corrupt: false
nbd モジュールの読み込み
$ sudo modprobe nbd
qcow2 イメージのバインド
$ sudo qemu-nbd -c /dev/nbd0 /var/lib/libvirt/images/Debian.qcow2
$ sudo fdisk -l /dev/nbd0
ディスク /dev/nbd0: 20 GiB, 21474836480 バイト, 41943040 セクタ
単位: セクタ (1 * 512 = 512 バイト)
セクタサイズ (論理 / 物理): 512 バイト / 512 バイト
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
ディスクラベルのタイプ: dos
ディスク識別子: 0x3c0808c8

デバイス    起動 開始位置 終了位置   セクタ サイズ Id タイプ
/dev/nbd0p1 *        2048   499711   497664   243M 83 Linux
/dev/nbd0p2        501758 41940991 41439234  19.8G  5 拡張領域
/dev/nbd0p5        501760 41940991 41439232  19.8G 83 Linux
kpartx でデバイスマッピング
$ sudo kpartx /dev/nbd0
nbd0p1 : 0 497664 /dev/nbd0 2048
nbd0p2 : 0 2 /dev/nbd0 501758
nbd0p5 : 0 41439232 /dev/dm-1 2
dm-crypt で暗号化されているのでデバイスをオープン
$ sudo cryptsetup open /dev/nbd0p5 crypt
Enter passphrase for /dev/nbd0p5:
lvm領域なのでスキャンする
$ sudo lvmdiskscan
    :
  /dev/mapper/crypt                                     [     <19.76 GiB] LVM physical volume
  /dev/nbd0p5                                           [     <19.76 GiB]
  /dev/debian-vg/root                                   [      18.75 GiB]
  /dev/debian-vg/swap_1                                 [       1.00 GiB]
    :
マウントして内容確認
$ sudo mount -o ro /dev/debian-vg/root /mnt
$ ls /mnt/
bin   dev  home        initrd.img.old  lib64       media  opt   root  sbin  sys  usr  vmlinuz
boot  etc  initrd.img  lib             lost+found  mnt    proc  run   srv   tmp  var  vmlinuz.old
Table of Contents

環境

$ dpkg-query -W kpartx qemu-utils fdisk cryptsetup lvm2 mount linux-image-`uname -r`
cryptsetup      2:2.0.4-2
fdisk   2.32.1-0.1
kpartx  0.7.7-1
linux-image-4.18.0-1-amd64      4.18.8-1
lvm2    2.02.176-4.1
mount   2.32.1-0.1
qemu-utils      1:2.12+dfsg-3
$ lsb_release -d
Description:    Debian GNU/Linux unstable (sid)
$ uname -m
x86_64
]]>
https://matoken.org/blog/2018/09/26/mount-qcow2-image/feed/ 0